<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/6/28
 * Time: 14:15
 */
class IndexController extends Controller{
    public function __constructor()
    {
        parent::__constructor();
    }
    public function insert()
    {
        $data=file_get_contents("php://input");
        $data=json_decode($data,true);

        //Log::write($data);
        if(empty($data))
        {
            self::failExit('数据不能为空');
        }
        $mongo = Mongodb();
        $mongo->selectDB( 'monitor' );
        $mongo->insert( 'monitor_log', $data );
        self::successExit();
    }
    public function get()
    {
        $mongo = new MongoClient("mongodb://192.168.0.224:27017", array('connect'=>true));// 立即连接
        $tt=new MongoCollection($mongo->selectDB('monitor'),'monitor_log');
        $page=isset($_GET['page'])?$_GET['page']:0;
        $tt=$tt->find([],['MacAddress'=>true,'DateTime'=>true,'UploadSpeed'=>true,'DownloadSpeed'=>true])->sort(['DateTime'=>-1]);
        $result=[];
        foreach($tt as $k=>$v)
        {
            $result[]=$v;
        }
        self::successExit($result);
    }
    public function post()
    {
       // public function __construct($config=array('host'=>'192.168.54.232','port'=>27017,'cmd'=>'$')){
        //$server = sprintf("mongodb://%s:%s", '192.168.0.224', '27017');

        self::failExit('post测试数据');
    }
}